package fr.cpe.j2ee.projet.war;

import java.util.Date;

import javax.faces.context.FacesContext;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

public class UserAdditionBean
{

	@Size(min = 2, max = 15)
	private String firstname;

	@Size(min = 2, max = 15)
	private String lastname;

	@Size(min = 2, max = 15)
	private String username;

	@Size(min = 6, max = 64)
	private String password;

	@Pattern(regexp = "^[\\w.-]+@[\\w.-]+\\.[a-zA-Z]{2,6}$")
	private String email;

	@Min(18)
	@Max(100)
	private int age;

	private Date indate;

	public String getFirstname()
	{
		return firstname;
	}

	public void setFirstname(String firstname)
	{
		this.firstname = firstname;
	}

	public String getLastname()
	{
		return lastname;
	}

	public void setLastname(String lastname)
	{
		this.lastname = lastname;
	}

	public String getUsername()
	{
		return username;
	}

	public void setUsername(String username)
	{
		this.username = username;
	}

	public String getPassword()
	{
		return password;
	}

	public void setPassword(String password)
	{
		this.password = password;
	}

	public String getEmail()
	{
		return email;
	}

	public void setEmail(String email)
	{
		this.email = email;
	}

	public int getAge()
	{
		return age;
	}

	public void setAge(int age)
	{
		this.age = age;
	}

	public Date getIndate()
	{
		return indate;
	}

	public void setIndate(Date indate)
	{
		this.indate = indate;
	}

	public void addEmployee()
	{
		/**
		 * Appel vers la méthode des bean entity d'ajout des utilisateurs
		 */

		System.out.println(this.username);

		UserTableBean userlist = (UserTableBean) FacesContext
				.getCurrentInstance().getExternalContext().getSessionMap()
				.get("userTableBean");
		userlist.addUser((UserAdditionBean) FacesContext.getCurrentInstance()
				.getExternalContext().getSessionMap().get("userAddition"));

	}
}
